﻿//
//  network_quality.cpp
//  wmp_av
//
//  Created by lokiyu on 2018/7/3.
//

#include <stdio.h>
#include "network_quality.h"

#include "listener.h"

template<> std::set<Stream::Network::Listener::Interface*>
Base::Listener::Interface<Stream::Network::Listener::Interface>::listener_ =
std::set<Stream::Network::Listener::Interface*>();

using namespace xcast;

class NetworkListener : public Base::Listener::Interface<Stream::Network::Listener::Interface> {
public:

    static void OnStreamActive(const char* stream_id, uint64_t uin, bool active) {
        for (auto it : listener_) {
            it->OnStreamActive(stream_id, uin, active);
        }
    }
    
    static void OnNetworkState(const char* stream_id, uint64_t uin, int quality) {
        for (auto it : listener_) {
            it->OnNetworkState(stream_id,uin,quality);
        }
    }
};


namespace Stream {
    namespace Network {
        namespace Listener {
            void Add(Interface* listener) {
                NetworkListener::Add(listener);
            }
            
            void Remove(Interface* listener) {
                NetworkListener::Remove(listener);
            }
        }
        
        namespace XcastEvent {
            void OnStreamActive(const char* stream_id, uint64_t uin, bool active) {
                NetworkListener::OnStreamActive(stream_id, uin, active);
            }
            
            void OnNetworkState(const char* stream_id, uint64_t uin, int quality){
                NetworkListener::OnNetworkState(stream_id,uin,quality);
            }
 
        }
    }
}
